package o;

import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;
import javax.net.ssl.SSLPeerUnverifiedException;

public final class fty {
    public static final fty ˋ = new a().ˋ();
    private final Set<d> ˎ;
    @Nullable
    private final fxe ˏ;

    public static final class a {
        private final List<d> ˎ = new ArrayList();

        public fty ˋ() {
            return new fty(new LinkedHashSet(this.ˎ), null);
        }
    }

    static final class d {
        final String ˊ;
        final String ˎ;
        final fxh ˏ;
        final String ॱ;

        boolean ˎ(String str) {
            if (!this.ˊ.startsWith("*.")) {
                return str.equals(this.ˎ);
            }
            int indexOf = str.indexOf(46);
            if ((str.length() - indexOf) - 1 != this.ˎ.length()) {
                return false;
            }
            if (str.regionMatches(false, indexOf + 1, this.ˎ, 0, this.ˎ.length())) {
                return true;
            }
            return false;
        }

        public boolean equals(Object obj) {
            return (obj instanceof d) && this.ˊ.equals(((d) obj).ˊ) && this.ॱ.equals(((d) obj).ॱ) && this.ˏ.equals(((d) obj).ˏ);
        }

        public int hashCode() {
            return ((((this.ˊ.hashCode() + 527) * 31) + this.ॱ.hashCode()) * 31) + this.ˏ.hashCode();
        }

        public String toString() {
            return this.ॱ + this.ˏ.ˏ();
        }
    }

    fty(Set<d> set, @Nullable fxe o_fxe) {
        this.ˎ = set;
        this.ˏ = o_fxe;
    }

    public boolean equals(@Nullable Object obj) {
        if (obj == this) {
            return true;
        }
        boolean z = (obj instanceof fty) && fvg.ॱ(this.ˏ, ((fty) obj).ˏ) && this.ˎ.equals(((fty) obj).ˎ);
        return z;
    }

    public int hashCode() {
        return ((this.ˏ != null ? this.ˏ.hashCode() : 0) * 31) + this.ˎ.hashCode();
    }

    public void ˊ(String str, List<Certificate> list) throws SSLPeerUnverifiedException {
        List ˏ = ˏ(str);
        if (!ˏ.isEmpty()) {
            int i;
            if (this.ˏ != null) {
                list = this.ˏ.ॱ(list, str);
            }
            int size = list.size();
            for (int i2 = 0; i2 < size; i2++) {
                X509Certificate x509Certificate = (X509Certificate) list.get(i2);
                int size2 = ˏ.size();
                int i3 = 0;
                Object obj = null;
                Object obj2 = null;
                while (i3 < size2) {
                    d dVar = (d) ˏ.get(i3);
                    if (dVar.ॱ.equals("sha256/")) {
                        if (obj == null) {
                            obj = ॱ(x509Certificate);
                        }
                        if (dVar.ˏ.equals(obj)) {
                            return;
                        }
                    } else if (dVar.ॱ.equals("sha1/")) {
                        if (obj2 == null) {
                            obj2 = ˋ(x509Certificate);
                        }
                        if (dVar.ˏ.equals(obj2)) {
                            return;
                        }
                    } else {
                        throw new AssertionError("unsupported hashAlgorithm: " + dVar.ॱ);
                    }
                    Object obj3 = obj;
                    i3++;
                    obj2 = obj2;
                    obj = obj3;
                }
            }
            StringBuilder append = new StringBuilder().append("Certificate pinning failure!").append("\n  Peer certificate chain:");
            int size3 = list.size();
            for (i = 0; i < size3; i++) {
                Certificate certificate = (X509Certificate) list.get(i);
                append.append("\n    ").append(ˏ(certificate)).append(": ").append(certificate.getSubjectDN().getName());
            }
            append.append("\n  Pinned certificates for ").append(str).append(":");
            size3 = ˏ.size();
            for (i = 0; i < size3; i++) {
                append.append("\n    ").append((d) ˏ.get(i));
            }
            throw new SSLPeerUnverifiedException(append.toString());
        }
    }

    List<d> ˏ(String str) {
        List<d> emptyList = Collections.emptyList();
        for (d dVar : this.ˎ) {
            if (dVar.ˎ(str)) {
                if (emptyList.isEmpty()) {
                    emptyList = new ArrayList();
                }
                emptyList.add(dVar);
            }
        }
        return emptyList;
    }

    fty ॱ(@Nullable fxe o_fxe) {
        if (fvg.ॱ(this.ˏ, (Object) o_fxe)) {
            return this;
        }
        return new fty(this.ˎ, o_fxe);
    }

    public static String ˏ(Certificate certificate) {
        if (certificate instanceof X509Certificate) {
            return "sha256/" + ॱ((X509Certificate) certificate).ˏ();
        }
        throw new IllegalArgumentException("Certificate pinning requires X509 certificates");
    }

    static fxh ˋ(X509Certificate x509Certificate) {
        return fxh.ˎ(x509Certificate.getPublicKey().getEncoded()).ˎ();
    }

    static fxh ॱ(X509Certificate x509Certificate) {
        return fxh.ˎ(x509Certificate.getPublicKey().getEncoded()).ॱ();
    }
}
